package DesignPrinciple.OpenClose.LSP.CorrectLSP;

public class Demo {
    public static void main(String[] args) {
        Rectangle rectangle = new Rectangle();
        rectangle.setLength(20);
        rectangle.setWidth(10);
        printLengthAndWidth(rectangle);
        resize(rectangle);
        printLengthAndWidth(rectangle);
        System.out.println("============================");
//        正方形和长方形现在无父子关系，不能调用resize
        Square square = new Square();
//        resize(square);
//        printLengthAndWidth(square);
    }

    public static void resize(Rectangle rectangle) {
//        宽比长小，扩宽
        while (rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
        }
    }

    public static void printLengthAndWidth(Rectangle rectangle) {
        System.out.println("Width: " + rectangle.getWidth() + "\tHeight: " + rectangle.getLength());
    }
}
